package com.changan.controller;

import com.changan.service.RedisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@Tag(name = "Redis的操作", description = "SpringBoot操作Redis")
@Validated
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisService redisService;

    @Operation(summary = "使用Redis操作List", description = "使用Redis操作List")
    @GetMapping("/setList")
    public void setList(String key, String value) {
        redisService.setList(key,value);
    }

    @Operation(summary = "设置Redis缓存", description = "设置Redis缓存")
    @GetMapping("/set")
    public void set(String key, String value) {
        redisService.setKey(key,value);
    }

    @Operation(summary = "根据Redis的key获取数据", description = "根据Redis的key获取数据")
    @GetMapping("/getKey")
    public String getKey(String key) {
        return redisService.getKey(key);
    }

    @Operation(summary = "设置Redis缓存-使用StringRedisTemplate", description = "设置Redis缓存")
    @GetMapping("/setUseString")
    public void setUseString(String key, String value) {
        redisService.setKeyUseString(key,value);
    }

    @Operation(summary = "删除key", description = "删除key")
    @GetMapping("/deleteKey")
    public void deleteKey(String key) {
        redisService.deleteKey(key);
    }

    @Operation(summary = "计数操作", description = "计数操作")
    @GetMapping("/incr")
    public void incr(String key,Integer number) {
        redisService.incr(key,number);
    }
}
